//
// Copyright (c) 2011, Peter Lane
// Licensed under the Academic Free License version 3.0

package fan.swtChartWrapper;

import fan.fwt.*;
import fan.gfx.Color;
import fan.sys.*;
import org.eclipse.swtchart.ILineSeries;
import org.eclipse.swtchart.ISeries;

public class LineSeriesPeer extends SeriesPeer {

  public static LineSeriesPeer make (fan.swtChartWrapper.LineSeries self) throws Exception {
    LineSeriesPeer peer = new LineSeriesPeer ();
    ((Series)self).peer = peer; // override base class's peer field
    return peer;
  }

  public void setISeries (ISeries series) {
    _series = series;
    _pointFormat.peer.setILabel (_series.getLabel ());
    _xErrorBar.peer.setIErrorBar (_series.getXErrorBar ());
    _yErrorBar.peer.setIErrorBar (_series.getYErrorBar ());
    if (_points != null) setYPoints (_points);
    ((ILineSeries)_series).enableArea (_enableArea);
    ((ILineSeries)_series).setLineColor (Fwt.get().color(_lineColour));
    ((ILineSeries)_series).setLineStyle (Utility.toSwt (_lineStyle));
    ((ILineSeries)_series).setLineWidth ((int)_lineWidth);
    ((ILineSeries)_series).setSymbolColor (Fwt.get().color(_symbolColour));
    ((ILineSeries)_series).setSymbolType (Utility.toSwt (_symbolType));
    ((ILineSeries)_series).setSymbolSize ((int)_symbolSize);
    ((ILineSeries)_series).enableStep (_enableStep);
    if (_enableStep) ((ILineSeries)_series).setSymbolType(org.eclipse.swtchart.ILineSeries.PlotSymbolType.NONE);
    _series.enableStack (_enableStack);
  }

  private List _points = null;
  public List points (fan.swtChartWrapper.LineSeries self) {
    return _points;
  }
  public void points (fan.swtChartWrapper.LineSeries self, List points) {
    _points = points.dup ();
    if (_series != null) setYPoints(_points);
  }

  private boolean _enableArea = false;
  public boolean enableArea (fan.swtChartWrapper.LineSeries self) { 
    return _enableArea;
  }
  public void enableArea (fan.swtChartWrapper.LineSeries self, boolean v) {
    _enableArea = v;
    if (_series != null) ((ILineSeries)_series).enableArea (_enableArea);
  }

  private boolean _enableStep = false;
  public boolean enableStep (fan.swtChartWrapper.LineSeries self) { 
    return _enableStep;
  }
  public void enableStep (fan.swtChartWrapper.LineSeries self, boolean v) {
    _enableStep = v;
    if (_series != null) ((ILineSeries)_series).enableStep (_enableStep);
  }

  private Color _lineColour = Color.blue;
  public Color lineColor (fan.swtChartWrapper.LineSeries self) { return _lineColour; }
  public void lineColor (fan.swtChartWrapper.LineSeries self, Color v) {
    _lineColour = v;
    if (_series != null) ((ILineSeries)_series).setLineColor (Fwt.get().color(_lineColour));
  }  
  
  private LineStyle _lineStyle = LineStyle.solid;
  public LineStyle lineStyle (fan.swtChartWrapper.LineSeries self) { return _lineStyle; }
  public void lineStyle (fan.swtChartWrapper.LineSeries self, LineStyle v) {
    _lineStyle = v;
    if (_series != null) ((ILineSeries)_series).setLineStyle (Utility.toSwt (_lineStyle));
  }

  private long _lineWidth = 1;
  public long lineWidth (fan.swtChartWrapper.LineSeries self) { return _lineWidth; }
  public void lineWidth (fan.swtChartWrapper.LineSeries self, long v) {
    if (v < 0) // trap negative values
      _lineWidth = 0;
    else
      _lineWidth = v;
    if (_series != null) ((ILineSeries)_series).setLineWidth ((int)_lineWidth);
  }

  private Color _symbolColour = Color.gray;
  public Color symbolColor (fan.swtChartWrapper.LineSeries self) { return _symbolColour; }
  public void symbolColor (fan.swtChartWrapper.LineSeries self, Color v) {
    _symbolColour = v;
    if (_series != null) ((ILineSeries)_series).setSymbolColor (Fwt.get().color(_symbolColour));
  }  
  
  private PlotSymbolType _symbolType = PlotSymbolType.circle;
  public PlotSymbolType symbolType (fan.swtChartWrapper.LineSeries self) { return _symbolType; }
  public void symbolType (fan.swtChartWrapper.LineSeries self, PlotSymbolType v) {
    _symbolType = v;
    if (_series != null) ((ILineSeries)_series).setSymbolType (Utility.toSwt (_symbolType));
  }

  private long _symbolSize = 4;
  public long symbolSize (fan.swtChartWrapper.LineSeries self) { return _symbolSize; }
  public void symbolSize (fan.swtChartWrapper.LineSeries self, long v) {
    if (v < 0) // trap negative values
      _symbolSize = 0;
    else
      _symbolSize = v;
    if (_series != null) ((ILineSeries)_series).setSymbolSize ((int)_symbolSize);
  }

  public ISeries.SeriesType type () { return ISeries.SeriesType.LINE; }
}
